﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using KhuyenMaiVang.DAL;

namespace KhuyenMaiVang.Infrastructure
{
    public class CustomRoleProvider:RoleProvider
    {
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetRolesForUser(string email)
        {
            KhuyenMaiVangDataContext db = new KhuyenMaiVangDataContext();
            List<User> lstUser = db.Users.ToList();
            if (lstUser.Exists(k => k.Email == email))
            {
                User curUser = lstUser.Find(
                    delegate(User u) { return u.Email == email; }
                );
                int? iGroup = curUser.GroupID;
                Group curGroup = db.Groups.ToList().Find(
                    delegate(Group g) { return g.ID == iGroup; }
                );
                return new String[] { curGroup.Name};
            }
            else
            {
                return new string[] { };
            }
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}